package cc.realxyq.springboot.db.mybatisplus.controller;

import cc.realxyq.springboot.db.mybatisplus.bean.SysUser;
import cc.realxyq.springboot.db.mybatisplus.service.SysUserService;
import cc.realxyq.springboot.db.utils.JsonResult;
import cc.realxyq.springboot.db.utils.ResultCode;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author : [buleing]
 * @version : [v1.0]
 * @description : [一句话描述该类的功能]
 * @createTime : [2021/6/11 12:12]
 * @updateUser : [buleing]
 * @updateTime : [2021/6/11 12:12]
 * @updateRemark : [说明本次修改内容]
 */
@RestController
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    @ApiOperation(value = "获得用户列表", notes = "", httpMethod = "GET")
    @GetMapping(value = "/users")
    public JsonResult listUser() {
        // 框架自带的方法
        List<SysUser> list = this.sysUserService.list(null);
        return new JsonResult(ResultCode.SUCCESS, list);
    }

    @ApiOperation(value = "根据用户名获得用户记录", notes = "名称不能为空", httpMethod = "GET")
    @ApiImplicitParam(dataType = "string", name = "name", value = "用户名", required = true)
    @GetMapping(value = "/users/{name}")
    public JsonResult getUserByName(@PathVariable("name") String name) {
        // 自定义的方法
        SysUser myuser = this.sysUserService.getUserByName(name);
        return new JsonResult(ResultCode.SUCCESS, myuser);
    }
}
